#include <unistd.h>
#include "../logs/clog.hpp"

void test_log(const std::string &name)
{
    INFO("%s", "测试开始");

    clog::Logger::ptr logger = clog::LoggerManager::GetInstance().getLogger(name);
    logger->debug( "%s", "测试日志");
    logger->info("%s", "测试日志");
    logger->warn( "%s", "测试日志");
    logger->error( "%s", "测试日志");
    logger->fatal( "%s", "测试日志");

    INFO("%s", "测试结束");
}

int main()
{
    const char *logger_name = "sync_logger";
    std::unique_ptr<clog::LoggerBuilder> bd(new clog::GlobalLoggerBuilder());
    bd->buildloggername(logger_name);
    bd->buildformatter("[%c][%p][%f:%l][%m]%n");
    bd->buildloggerlevel(clog::LogLevel::value::DEBUG);
    bd->buildloggertype(clog::LoggerType::LOG_SYNC);
    bd->buildsink<clog::StdoutSink>();
    bd->buildsink<clog::FileSink>("./logfile/sync.log");
    bd->buildsink<clog::RollBySizeSink>("./logfile/roll-by-size-sync.log-", 1024 * 1024);
    bd->build();
    test_log(logger_name);

    return 0;
}